import path from "path";

const config = {
  projectName: "test-dux-taro",
  date: "2024-1-14",
  designWidth: 750,
  deviceRatio: {
    375: 2,
    640: 2.34 / 2,
    750: process.env.TARO_ENV === "h5" ? 640 / 750 : 1,
    828: 1.81 / 2,
  },
  sourceRoot: "src",
  outputRoot: `dist/${process.env.TARO_ENV}`,
  plugins: [],
  defineConstants: {},
  copy: {
    patterns: [],
    options: {},
  },
  framework: "react",
  compiler: {
    type: "webpack5",
    // 仅 webpack5 支持依赖预编译配置
    prebundle: {
      /**
       * 3.6.7版本小程序命令行封装报错，暂时关掉此选项解决
       */
      enable: false,
      exclude: ["taro-design"],
    },
  },
  cache: {
    enable: false, // Webpack 持久化缓存配置，建议开启。默认配置请参考：https://docs.taro.zone/docs/config-detail#cache
    buildDependencies: {
      config: [path.resolve(__dirname, "..", "src/theme/theme.scss")],
    },
  },
  sass: {
    resource: [path.resolve(__dirname, "..", "src/theme/theme.scss")],
  },
  alias: {
    '@/components': path.resolve(__dirname, '..', 'src/components'),
    '@/static': path.resolve(__dirname, '..', 'src/static'),
    '@/utils': path.resolve(__dirname, '..', 'src/utils'),
    '@/theme': path.resolve(__dirname, '..', 'src/theme'),
  },
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {},
      },
      url: {
        enable: true,
        config: {
          limit: 1024, // 设定转换尺寸上限
        },
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: "module", // 转换模式，取值为 global/module
          generateScopedName: "[name]__[local]___[hash:base64:5]",
        },
      },
    },
  },
  h5: {
    publicPath: "/",
    staticDirectory: "static",
    postcss: {
      // pxtransform: {
      //   enable: true,
      //   config: {},
      // },
      autoprefixer: {
        enable: true,
        config: {},
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: "module", // 转换模式，取值为 global/module
          generateScopedName: "[name]__[local]___[hash:base64:5]",
        },
      },
    },
  },
  rn: {
    appName: "taroDemo",
    output: {
      ios: "./ios/main.jsbundle",
      iosAssetsDest: "./ios",
      android: "./android/app/src/main/assets/index.android.bundle",
      androidAssetsDest: "./android/app/src/main/res",
      // iosSourceMapUrl: '',
      iosSourcemapOutput: "./ios/main.map",
      // iosSourcemapSourcesRoot: '',
      // androidSourceMapUrl: '',
      androidSourcemapOutput: "./android/app/src/main/assets/index.android.map",
      // androidSourcemapSourcesRoot: '',
    },
    postcss: {
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
      },
    },
    resolve: {
      include: ["taro-design"],
    },
  },
};

module.exports = function (merge) {
  if (process.env.NODE_ENV === "development") {
    return merge({}, config, require("./dev"));
  }
  return merge({}, config, require("./prod"));
};
